﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FootballProject.DAL.DatatAccessLib;

namespace FootballProject.BL.BusinessManagers
{
    /// <summary>
    /// Author: Ivan Shikht
    /// </summary>
    class AwayTeamManager
    {
        #region Fields
        private readonly EntitiesContext _context;
        #endregion

        #region Constructors
        public AwayTeamManager()
        {
            _context = new EntitiesContext();
        }
        #endregion

        #region Methods
        public List<AwayTeam> FindAll()
        {
            IQueryable<AwayTeam> rAwayTeam = from awayTeam in _context.AwayTeamSet
                                             select awayTeam;
            return rAwayTeam.ToList();
        }

        public List<AwayTeam> FindAwayTeamsByTeam(Team team)
        {
            IQueryable<AwayTeam> rAwayTeam = from awayTeam in _context.AwayTeamSet
                                             where awayTeam.Teams == team
                                             select awayTeam;
            return rAwayTeam.ToList();
        }

        public AwayTeam FindAwayTeamById(Guid awayTeamId)
        {
            IQueryable<AwayTeam> rAwayTeam = from awayTeam in _context.AwayTeamSet
                                             where awayTeam.ATeamID == awayTeamId
                                             select awayTeam;
            return rAwayTeam.First();
        }

        public void UpdateAwayTeam(AwayTeam awayTeam)
        {
            _context.Attach(awayTeam);
            awayTeam.SetAllModified(_context);
            _context.SaveChanges();
        }

        public void AddAwayTeam(AwayTeam awayTeam)
        {
            _context.AddToAwayTeamSet(awayTeam);
            _context.SaveChanges();
        }


        public void DeleteAwayTeam(AwayTeam awayTeam)
        {
            _context.Attach(awayTeam);
            _context.DeleteObject(awayTeam);
            _context.SaveChanges();
        }
        #endregion
    }
}
